import request from '@/config/axios'
import { ChannelRuleVO,ChannelIpRuleVO } from './types'

export interface ChannelVO {
  id: number
  modelId: number
  contentModelId: number
  siteId: number
  parentId: number
  name: string
  path: string
  nodePath: string
  workflowId: number
  sort: number
  listStatus: number
  recycleStatus: number
}

export interface ChannelPageReqVO extends PageParam {
  modelId?: number
  contentModelId?: number
  siteId?: number
  parentId?: number
  name?: string
  path?: string
  nodePath?: string
  workflowId?: number
  sort?: number
  listStatus?: number
  recycleStatus?: number
  filterType?: number
  createTime?: Date[]
}

export interface ChannelExcelReqVO {
  modelId?: number
  contentModelId?: number
  siteId?: number
  parentId?: number
  name?: string
  path?: string
  nodePath?: string
  workflowId?: number
  sort?: number
  listStatus?: number
  recycleStatus?: number
  createTime?: Date[]
}

export interface ChannelScoreVO {
  id: number
  oneContentScore: number
}
export interface ChannelDayVO {
  id: number
  contentUpdateDay: number
}
export interface ChannelBatchCreateVO {
  channelId: number
  parentId: number|undefined
  names: string
}
// 查询栏目列表
export const getChannelListApi = async (params?: ChannelPageReqVO) => {
  return await request.get({ url: '/cms/channel/tree', params })
}

//获取内容的栏目树
export const getContentChannelTreeApi = async (params?: ChannelPageReqVO) => {
  return await request.get({ url: '/cms/channel/getContentChannelTree', params })
}

// 查询回收站栏目列表
export const getRecycleChannelListApi = async (params?: ChannelPageReqVO) => {
  return await request.get({ url: '/cms/channel/getRecycleTree', params })
}

// 查询栏目（精简)列表
export const listSimpleChannelApi = async (siteId?: number) => {
  if (!siteId) {
    return await request.get({ url: '/cms/channel/list-all-simple' })
  } else {
    return await request.get({ url: '/cms/channel/list-all-simple?siteId=' + siteId })
  }
}

// 查询栏目详情
export const getChannelApi = async (id: number) => {
  return await request.get({ url: '/cms/channel/get?id=' + id })
}
//查询栏目规则配置
export const getChannelRuleApi = async (id: number) => {
  return await request.get({ url: '/cms/channel/getChannelRule?id=' + id })
}

// 新增栏目
export const createChannelApi = async (data: ChannelVO) => {
  return await request.post({ url: '/cms/channel/create', data })
}

// 修改栏目
export const updateChannelApi = async (data: ChannelVO) => {
  return await request.put({ url: '/cms/channel/update', data })
}

//修改栏目采集规则配置
export const updateChannelRuleApi = async (data: ChannelRuleVO) => {
  return await request.post({ url: '/cms/channel/updateChannelRule', data })
}

// 删除栏目到回收站
export const recycleChannelApi = async (id: number) => {
  return await request.post({ url: '/cms/channel/recycle?id=' + id })
}
// 删除栏目
export const deleteChannelApi = async (id: number) => {
  return await request.post({ url: '/cms/channel/delete?id=' + id })
}

//还原栏目
export const restoreChannelApi = async (id: number | undefined) => {
  if (id) {
    return await request.post({ url: '/cms/channel/restore?id=' + id })
  }
}

// 导出栏目 Excel
export const exportChannelApi = async (params: ChannelExcelReqVO) => {
  return await request.download({ url: '/cms/channel/export-excel', params })
}
// 修改栏目绩效值
export const updateChannelScoreApi = async (data: ChannelScoreVO) => {
  return await request.post({ url: '/cms/channel/updateScore', data })
}
// 修改栏目更新要求值
export const updateChannelDayApi = async (data: ChannelDayVO) => {
  return await request.post({ url: '/cms/channel/updateContentDay', data })
}
// 查询栏目访问量列表
export const getChannelViewListApi = async (params?: ChannelPageReqVO) => {
  return await request.get({ url: '/cms/channel/getChannelView', params })
}
//修改栏目IP访问规则配置
export const updateChannelIpRuleApi = async (data: ChannelIpRuleVO) => {
  return await request.post({ url: '/cms/channel/updateChannelIpRule', data })
}
// 批量新增栏目
export const batchCreateChannelApi = async (data: ChannelBatchCreateVO) => {
  return await request.post({ url: '/cms/channel/batchCreate', data })
}